package taller2.controller.listeners;

import java.awt.Rectangle;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

import taller2.view.components.SwitchBox;
import taller2.view.menus.CodeBrowser;

public class ToggleButtonHandler extends MouseAdapter {
		SwitchBox box;
		CodeBrowser browser;
		
		public ToggleButtonHandler(SwitchBox box,CodeBrowser browser){
			this.box = box;
			this.browser = browser;
		}
		
        public void mouseReleased( MouseEvent e ) {
            if(new Rectangle( box.getPreferredSize() ).contains( e.getPoint() )){
            	boolean selected = box.isSelected();
            	box.setSelected( !selected );
            	
            	if(!selected){
            		browser.startAutoscroll();
            	}else{
            		browser.stopAutoscroll();
            	}
            } 
        }
}
